package com.hkts.beltweigher.config;


import com.hkts.beltweigher.opc.ClientExampleRunner;
import com.hkts.beltweigher.opc.EastDataAcquisitionClient;
import com.hkts.beltweigher.websocket.WebsocketServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.concurrent.CompletableFuture;

/**
 * @ClassNameWebsocketRun
 * @Description
 * @Author yck
 * @Date9/8/2022 下午5:53
 * @Version V1.0
 **/
@Component
@Order(1)
@Slf4j
public class WebsocketRun implements ApplicationRunner {
    @Override
    public void run(ApplicationArguments args) throws Exception {
       //opc_ua

        CompletableFuture<Void> voidCompletableFuture1 = CompletableFuture.runAsync(() -> {
            try {
                EastDataAcquisitionClient client=new EastDataAcquisitionClient();
                client.setOpcUrl("192.168.205.130:4840");
                client.setTableDescribte("煅烧皮带秤东线");
                client.setOpcId("1");
                String tEndpointUrl = "opc.tcp://192.168.205.130:4840";
                new ClientExampleRunner(client, tEndpointUrl).run();
                log.info("read run.....");
            } catch (Exception e) {
                log.info("ReadNodeExampleError:" + e.getMessage());
            }
        });
       //websocket
        CompletableFuture<Void> voidCompletableFuture2 = CompletableFuture.runAsync(() -> {
            try {
                log.info("netty 消息长连接启动");
                new WebsocketServer(8139).start();
            } catch (Exception e) {
                System.out.println("NettyServerError:" + e.getMessage());
            }
        });
    }
}
